package com.luyu.exception;

import com.luyu.res.ResultRes;
import com.luyu.util.ResponseUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

/**
 * @author luYu
 */
@RestControllerAdvice
public class RestExceptionHandler {


    @ExceptionHandler(Exception.class)
    public void catchException(Exception e, HttpServletResponse response) throws IOException {
        System.out.println("出现异常");
        e.printStackTrace();
        ResponseUtil.returnErrorMsg(response,ResultRes.error(e.getMessage()));
    }
}
